import CryptoJS from 'crypto-js'

/* 参数加密 */
const encrypt = function(word, keyStr) {
  keyStr = keyStr ? keyStr : 'lzkjabcdefg123we';
  var key = CryptoJS.enc.Utf8.parse(keyStr);
  var srcs = CryptoJS.enc.Utf8.parse(word);
  var encrypted = CryptoJS.AES.encrypt(srcs, key, { mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.Pkcs7 });
  return encrypted.toString();
};

/**
* 参数解密 
* @param word 需要加密的参数字符串
* @param keyStr 指定加密字段
*/
const decrypt = function(word, keyStr) {
  keyStr = keyStr ? keyStr : 'lzkjabcdefg123we';
  var key = CryptoJS.enc.Utf8.parse(keyStr);
  var decrypt = CryptoJS.AES.decrypt(word, key, { mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.Pkcs7 });
  return CryptoJS.enc.Utf8.stringify(decrypt).toString();
};


module.exports = {
  encrypt,
  decrypt
}